#include "HeroElement.hpp"

const float HeroElement::HEIGHT = 1.8f;
const float HeroElement::FRICTION = 0.3f;
const float HeroElement::MASS = 70.0f;
const float HeroElement::RESTITUTION = 0.0f;
const float HeroElement::WIDTH = 0.6f;

HeroElement::HeroElement(float x, float y, b2World* world) {
    this->flying = false;
    this->grabbedBox = NULL;
    this->lookingAtRight = true;
    this->onAir = false;
    this->stopping = false;

    b2BodyDef bodyDefinition;
    bodyDefinition.userData = this;
    bodyDefinition.position.Set(x, y);
    bodyDefinition.type = b2_dynamicBody;
    bodyDefinition.bullet = true;
    bodyDefinition.fixedRotation = true;

    b2PolygonShape shape;
    shape.SetAsBox(HeroElement::WIDTH / 2.0f, HeroElement::HEIGHT / 2.0f);

    b2FixtureDef fixtureDefinition;
    fixtureDefinition.shape = &shape;
    fixtureDefinition.density = HeroElement::MASS / (HeroElement::WIDTH * HeroElement::HEIGHT);
    fixtureDefinition.friction = HeroElement::FRICTION;
    fixtureDefinition.restitution = HeroElement::RESTITUTION;

    this->body = world->CreateBody(&bodyDefinition);
    this->mainFixture = this->body->CreateFixture(&fixtureDefinition);

    // Foot sensor (to know if jump is available).
    shape.SetAsBox(0.29f, 0.01f, b2Vec2(0.0f, -0.9f), 0.0f);
    fixtureDefinition.isSensor = true;
    this->body->CreateFixture(&fixtureDefinition);
}

bool HeroElement::isHero() {
    return true;
}
